﻿namespace Shortcuts.Views
{
    using Microsoft.Phone.Controls;
    using Shortcuts.Common;
    using System;
    using System.Windows.Navigation;

    public partial class NavigationPage : PhoneApplicationPage
    {
        const string SettingsKey = "settings";

        public NavigationPage()
        {
            InitializeComponent();
        }

        protected override void OnNavigatedTo(System.Windows.Navigation.NavigationEventArgs e)
        {
            if (e.NavigationMode == NavigationMode.New && NavigationContext.QueryString.ContainsKey(SettingsKey))
            {
                Settings settings = Settings.None;
                try
                {
                    settings = (Settings)Enum.Parse(typeof(Settings), NavigationContext.QueryString[SettingsKey], true);
                }
                catch { }

                if (settings != Settings.None)
                {
                    settings.ToTile().Launch();
                }
            }

            throw new Exceptions.ExitException();
        }
    }
}